package cn.yunyichina.provider.base.service.impl;

import cn.yunyichina.provider.base.dao.ImageTemplateDao;
import cn.yunyichina.provider.base.dao.ImageTemplateListDao;
import cn.yunyichina.provider.base.entity.ImageTemplate;
import cn.yunyichina.provider.base.entity.ImageTemplateList;
import cn.yunyichina.provider.base.vo.ImageTemplateListResponse;
import cn.yunyichina.provider.iface.entity.common.Response;
import cn.yunyichina.utils.convert.JsonUtils;
import com.alibaba.druid.support.json.JSONUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * Created by Joe.zhou on 2017/8/9.
 */
@Service
public class ImageTemplateServiceImpl {

    private static final Logger logger = LoggerFactory.getLogger(ImageTemplateServiceImpl.class);

    @Autowired
    private ImageTemplateDao imageTemplateDao;

    @Autowired
    private ImageTemplateListDao imageTemplateListDao;


    /**
     * 获取图片模板
     * @param data
     * @interfaceName: yyt.base.imagetemplate.get
     * @return
     */
    public Response getImageTemplate(String data) {

        logger.info("[ImageTemplateServiceImpl.getImageTemplate]  json -->" + JsonUtils.toJsonString(data));

        Response response = new Response();
        ImageTemplate imageTemplate = JsonUtils.parseObject(data , ImageTemplate.class);

        List<ImageTemplate> imageTemplates = imageTemplateDao.select(imageTemplate);

        if(imageTemplates.size() > 0){
            response.setResultCodeAndMessageAndResult("0", "查询成功!" , JsonUtils.toJsonString(imageTemplates));
        }else{
            response.setResultCodeAndMessage(Response.FAILURE_CODE , "查无结果");
        }

        return response;

    }




    /**
     * 根据code获取图片模板
     * @param data
     * @interfaceName: yyt.base.image.template.by.code.get
     * @return
     */
    public Response getImageTemplateByCode(String data) {

        logger.info("[ImageTemplateServiceImpl.getImageTemplateByCode]  json -->" + JsonUtils.toJsonString(data));

        Response response = new Response();
        ImageTemplate imageTemplate = JsonUtils.parseObject(data , ImageTemplate.class);

        List<ImageTemplateList> imageList = imageTemplateListDao.selectTemplateByCode(imageTemplate.getTemplateCode());

        if(imageList.size() > 0){
            response.setResultCodeAndMessageAndResult("0", "查询成功!" , JsonUtils.toJsonString(imageList));
        }else{
            response.setResultCodeAndMessage(Response.FAILURE_CODE , "查无结果");
        }

        return response;

    }
}
